<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <input type="text" />
        <span></span>
        <script>
            let input = document.querySelector('input');
            let span = document.querySelector('span');
            let obj = {};

            Object.defineProperty(obj, 'text', {
                get() {
                    console.log('获取数据了');
                },
                set(newValue) {
                    console.log('数据更新了');
                    input.value = newValue;
                    span.innerHTML = newValue;
                },
            });
            input.addEventListener('keyup', function (e) {
                obj.text = e.target.value;
            });
        </script>
    </body>
</html>
